﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server
{
    public sealed class Command
    {
        public enum CommandType { EXIT, DISPLAY, EASY, MEDIUM, HARD, UNDO, HUMAN_AI, AI_AI }
        private CommandType type;

        public static readonly Command Exit = new Command(CommandType.EXIT);
        public static readonly Command Display = new Command(CommandType.DISPLAY);
        public static readonly Command Easy = new Command(CommandType.EASY);
        public static readonly Command Medium = new Command(CommandType.MEDIUM);
        public static readonly Command Hard = new Command(CommandType.HARD);
        public static readonly Command Undo = new Command(CommandType.UNDO);
        public static readonly Command Human_AI = new Command(CommandType.HUMAN_AI);
        public static readonly Command AI_AI = new Command(CommandType.AI_AI);

        private Command(CommandType c)
        {
            type = c;
        }

        public CommandType CommandName
        {
            get
            {
                return type;
            }
        }

        public static Command Parse(string s)
        {
            s = s.ToUpper().Trim();
            if (s.Equals("EXIT"))
                return Exit;
            else if (s.Equals("DISPLAY"))
                return Display;
            else if (s.Equals("EASY"))
                return Easy;
            else if (s.Equals("MEDIUM"))
                return Medium;
            else if (s.Equals("HARD"))
                return Hard;
            else if (s.Equals("HUMAN-AI") || s.Equals("HUMAN_AI"))
                return Human_AI;
            else if (s.Equals("AI-AI") || s.Equals("AI_AI"))
                return AI_AI;
            else
                throw new ArgumentException();
        }

        public static bool TryParse(string s, out Command c)
        {
            try
            {
                c = Parse(s);
                return true;
            }
            catch (ArgumentException)
            {
                c = null;
                return false;
            }
        }
    }
}
